// 店铺信息
function shop_i() {
  //   实例化vue
  new Vue({
    el: "#shop_i",
    data() {
      return {
        shopInfo: "", //店铺信息
        coupon_list: "", //优惠券
        top_img: "", //顶部图片
        hot_list: "", //热销尖货
        hot_list_topImg: "", //热销尖货-大图
        hot_list_otImg: "", //热销尖货-小图
        new_list: "", //当季新品
        new_list_topImg: "", //当季新品-大图
        new_list_otImg: "", //当季新品-小图
        pro_list1: "", //产品列表1
        pro_list2: "", //产品列表2
      }

    },
    methods: {
      // 获取店铺信息
      getShopInfo: function() {
        let shopInfoUrl = `${urlParam.domain()}api/shop/shopInfo`; //店铺信息 
        let that = this;
        axios({
          method: "post",
          url: shopInfoUrl,
          params: {
            token: urlParam.token(),
            id: 1
          }
        }).then(function(res) {
          that.shopInfo = res.data.data;
        }).then(function() {
          let shopTempUrl = `${urlParam.domain()}api/shopDecoration/list`; //店铺模板
          axios({
            method: "get",
            url: shopTempUrl,
            params: {
              token: urlParam.token(),
              id: 1
            }
          }).then(function(res) {
            console.log(res.data.data);
            that.coupon_list = res.data.data.couponManageList;
            that.top_img = res.data.data.shopTemplateList[0];
            that.hot_list = res.data.data.shopTemplateList[1];
            //过滤数组
            that.hot_list_topImg = res.data.data.shopTemplateList[1].shopPictUrlList[0]; //大图
            let arr1 = res.data.data.shopTemplateList[1].shopPictUrlList;
            arr1.shift(); //删除第一组大图数据
            that.hot_list_otImg = arr1; // 其他的小图

            that.new_list = res.data.data.shopTemplateList[2];
            that.new_list_topImg = res.data.data.shopTemplateList[1].shopPictUrlList[0]; //大图
            let arr2 = res.data.data.shopTemplateList[1].shopPictUrlList;
            arr2.shift(); //删除第一组大图数据
            that.new_list_otImg = arr2; // 其他的小图

            that.pro_list1 = res.data.data.shopTemplateList[3];
            that.pro_list2 = res.data.data.shopTemplateList[4];
          })
        })

      },
      //关注店铺
      loveShop: function() {
        let that = this;
        let loveUrl = `${urlParam.domain()}api/user/focusShop`;
        axios({
          method: "post",
          url: loveUrl,
          params: {
            token: urlParam.token(),
            sellerId: 1,
            type: that.shopInfo.follow
          },

        }).then(function(res) {
          // 实时刷新关注
          if (res.data.code == 1) {
            if (that.shopInfo.follow == 0) {
              that.shopInfo.follow = 1;
            } else {
              that.shopInfo.follow = 0;
            }
          }
        })
      },
      // 联系卖家
      contactSeller: function() {
        let that = this;
        let { QQ } = that.shopInfo;
        alert(`qq号码是${QQ}`)
      },
      //领取优惠券
      getCoupons: function(index) {
        let that = this;
        let couponsUrl = `${urlParam.domain()}api/myCoupon/getCoupons`; //领取优惠券
        axios({
          url: couponsUrl,
          method: "post",
          params: {
            token: urlParam.token(),
            StartTime: that.coupon_list[index].startTime,
            businessId: "1",
            couponNo: that.coupon_list[index].couponNo,
            couponType: 1,
            endTime: that.coupon_list[index].endTime,
          },
        }).then(function(res) {
          let couponsCode = res.data.code; //优惠券状态码
          if (couponsCode == 1) {
            alert("您已经成功领取了优惠券！");
            console.log(res)
          } else {
            alert("您已经领过优惠券了，不能重复领取")
          }
        })
      },
    },
    created() {
      this.getShopInfo();
    }
  })
}

// 店铺_促销/全部商品/上新
function shop_common(type) {
  // mockdata
  let mockData = Mock.mock({
    "shop_name": "@ctitle(5, 13)",
    "pro_list|4-8": [{
      'img': "@image('498x498',#eac7ce)",
      'title': "@ctitle(5, 10)",
      'sellprice|100-200.2': 239.00,
      'sellcount|800-1000': 800,
      'dingzhi|0-1': 0,
      'rexiao|0-1': 0,
      'shangxin|0-1': 0
    }]
  });
  //   实例化vue
  new Vue({
    el: "#shop_common",
    data() {
      return {
        type: type, //当前页面type
        type_num: null, //当前页面type对应的tag
        pro_list: null, //产品列表
        showTuijian: false,
        tuijian_type: 1,
        shaixuan_type: 1
      }
    },
    methods: {
      //获取店铺信息
      getShopInfo: function(type) {
        let that = this;

        if (type === "all") {
          that.type_num = 1;
          let url = `${urlParam.domain()}api/shop/commodityList` //全部商品
          axios({
            method: "post",
            url,
            params: {
              token: urlParam.token(),
              pagesize: 1,
              productId: 1,
              userId: 1
            }

          }).then(function(res) {
            that.pro_list = res.data.data.commodityList;
            console.log(res.data.data)
          })
        } else if (type === 'cuxiao') {
          that.type_num = 2;
          let url = `${urlParam.domain()}api/shop/getSaleActivityCommodityList` //促销活动商品
          axios({
            method: "post",
            url,
            params: {
              token: urlParam.token(),
              pagesize: 1,
              productId: 1,
              userId: 1,
              saleActivityId: 5,
            }

          }).then(function(res) {
            that.pro_list = res.data.data.commodityList;
            console.log(res.data.data)
          })
        } else if (type === 'new') {
          that.type_num = 3;
          let url = `${urlParam.domain()}api/shop/getNewCommodityList` //上新商品
          axios({
            method: "post",
            url,
            params: {
              token: urlParam.token(),
              pagesize: 1,
              productId: 0,
              userId: 1,
            }

          }).then(function(res) {
            that.pro_list = res.data.data.commodityList;
            console.log(res.data.data)
          })
        }

      },
      // 排序规则
      filter: function() {

      },

      // 获得店铺信息
      getShop: function() {
        this.pro_list = mockData.pro_list;
        if (type === 'all') {
          this.type_num = 1;
        } else if (type === 'cuxiao') {
          this.type_num = 2;
        } else if (type === 'new') {
          this.type_num = 3;
        }
      },
      toggleTuijian: function() {
        this.showTuijian = !this.showTuijian;
      },
      changeTuijianType: function(n) {
        this.tuijian_type = n;
        this.shaixuan_type = 1;
        this.showTuijian = !this.showTuijian;
      },
      changeShaixuanType: function(n) {
        this.shaixuan_type = n;
      }
    },
    created() {
      this.getShopInfo(type);
      // this.getShop();
    }
  })
}

// 店铺_搜索
function shop_search() {
  // mockdata
  let mockData = Mock.mock({
    "shop_list|4-8": [{
      "shop_name": "@ctitle(5, 13)",
      "shop_img": "@image('117x117',#eac7ce)",
      "shop_location": "福建省 福州市",
      "pro_list|3": [{
        'img': "@image('330x336',#eac7ce)",
        'sellprice|100-200.2': 239.00
      }]
    }]

  });
  //   实例化vue
  new Vue({
    el: "#shop_search",
    data() {
      return {
        shop_list: [],
        shaixuan_type: 1
      }
    },
    methods: {
      // 获得店铺列表
      getShop: function() {
        this.shop_list = mockData.shop_list;
      },
      changeShaixuanType: function(n) {
        this.shaixuan_type = n;
      }
    },
    created() {
      this.getShop();
    }
  })
}

//热销
function rexiao() {
  // mockdata
  let mockData = Mock.mock({
    "pro_list|5-8": [{
      'img': "@image('498x498',#eac7ce)",
      'title': "@ctitle(5, 10)",
      'sellprice|100-200.2': 239.00,
      'sellcount|800-1000': 800,
      'dingzhi|0-1': 0,
      'xinpin|0-1': 0,
      'quan|0-1': 0
    }]
  });
  //   实例化vue
  new Vue({
    el: "#rexiao",
    data() {
      return {
        pro_list: null, //产品列表
        type: 1
      }
    },
    methods: {
      // 获得产品列表
      getList: function() {
        this.pro_list = mockData.pro_list;
      },
      changeType: function(type) {
        this.type = type;
      }
    },
    created() {
      this.getList();
    }
  })
}